package com.mlt.test;

import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.pdfclown.documents.Document;
import org.pdfclown.files.File;
import org.pdfclown.tools.Renderer;

public class ContentRenderingSample {
	public static void go() {
		String filePath = "prisma.pdf";

		// 1. Open the PDF file!
		File file;
		try {
			file = new File(filePath);
		} catch (Exception e) {
			throw new RuntimeException(filePath + " file access error.", e);
		}

		// 2. Get the PDF document!
		Document document = file.getDocument();

		// 3. Rasterize the first page!
		Renderer renderer = new Renderer();
		BufferedImage image = renderer.render(document.getPages().get(0), new Dimension(1400, 850));

		// 4. Save the rasterized image!
		try {
			ImageIO.write(image, "jpg", new java.io.File("ContentRenderingSample.jpg"));
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	
	public static void main(String[] args) {
		go();
	}
}
